export default {
  mounted(el, binding) {
    const scrollToBottom = () => {
      el.scrollTop = el.scrollHeight;
    };
    
    // 初始滚动到底部
    scrollToBottom();
    
    // 监听子元素变化
    const observer = new MutationObserver(() => {
      if (binding.value === undefined || binding.value) {
        scrollToBottom();
      }
    });
    
    observer.observe(el, {
      childList: true,
      subtree: true
    });
    
    // 保存observer实例以便销毁
    el._scrollBottomObserver = observer;
  },
  
  beforeUnmount(el) {
    // 清理observer
    if (el._scrollBottomObserver) {
      el._scrollBottomObserver.disconnect();
      delete el._scrollBottomObserver;
    }
  }
} 